package com.mall.service.user;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.user.TransferAuditService;
import com.mall.custom.dao.read.TransferAuditReadMapper;
import com.mall.custom.dao.write.TransferAuditWriteMapper;
import com.mall.pojo.TransferAudit;
import com.mall.pojo.TransferAuditExample;

@Service
public class TransferAuditServiceImpl implements TransferAuditService {
	@Autowired
	private TransferAuditWriteMapper transferAuditWriteMapper;
	@Autowired
	private TransferAuditReadMapper transferAuditReadMapper;

	@Override
	public int insertTransferAudit(TransferAudit transferAudit) {
		transferAudit.setGmtCreate(new Date());
		transferAudit.setGmtModify(new Date());
		return this.transferAuditWriteMapper.insert(transferAudit);
	}

	@Override
	public int modifyTransferAudit(TransferAudit transferAudit) {
		transferAudit.setGmtModify(new Date());
		return this.transferAuditWriteMapper.updateByPrimaryKey(transferAudit);
	}

	@Override
	public List<TransferAudit> getTransferAuditListByUserAndKey(Long userId, Integer onlyKey, Integer status,String phone) {
		TransferAuditExample example = new TransferAuditExample();
		example.setOrderByClause("gmt_modify desc");
		com.mall.pojo.TransferAuditExample.Criteria criteria = example.createCriteria();
		if(onlyKey != null){
			criteria.andCommOnlyKeyEqualTo(onlyKey);
		}
		if(userId != null){
			criteria.andUserIdEqualTo(userId);
		}
		if(status != null){
			criteria.andStatusEqualTo(status);
		}
		if(phone != null){
			criteria.andPhoneLike(phone);
		}
		return this.transferAuditReadMapper.selectByExample(example);
	}

	@Override
	public TransferAudit getTransferAuditById(Long id) {
		return this.transferAuditReadMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<TransferAudit> getTransferAuditListByExample(TransferAuditExample transferAuditExample) {
		// TODO Auto-generated method stub
		return this.transferAuditReadMapper.selectByExample(transferAuditExample);
	}

}
